package com.ruoyi.infoManagement.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.infoManagement.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
@RestController

@RequestMapping("/infoManagement/user")
public class UserController extends BaseController {
  @Autowired
  UserService userService;
  @PreAuthorize("@ss.hasPermi('infoManagement:user:import')")
  @Log(title = "用户管理", businessType = BusinessType.IMPORT)
  @PostMapping("/importData")
  public AjaxResult importDataInfoManagement(MultipartFile file, boolean updateSupport) throws Exception
  {
    ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
    List<SysUser> userList = util.importExcel(file.getInputStream());
    String operName = getUsername();
    String message = userService.importUser(userList, updateSupport, operName);
    return AjaxResult.success(message);
  }
}
